//
//  ZCViewController.m
//  WeiDuYY
//
//  Created by shy 佳佳 on 2019/1/24.
//  Copyright © 2019 W ke杨. All rights reserved.
//

#import "ZCViewController.h"
#import <SDAutoLayout.h>
#import "LgViewController.h"
#import "AFNetworking.h"
//#import "SHMD5Tool.h"
#import "NSString+AES.h"
@interface ZCViewController ()
{
    //注册输入框
    UITextField *Nametf,*Sextf2,*Yeartf3,*Phonetf4,*Emailtf5,*Passwordtf6,*ConfirmPasswordtf7;
    NSString *sexBool;//性别判断
}
@end

@implementation ZCViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置登录背景图片
    self.view.backgroundColor=[UIColor whiteColor];
    UIImageView *img=[[UIImageView alloc]initWithFrame:self.view.frame];
    img.image=[UIImage imageNamed:@"Bitmap"];
    img.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    [self.view addSubview:img];
    self.view.backgroundColor=[UIColor whiteColor];
    [self viewvalue];
}

-(void)viewvalue{
    UIView *vi=[UIView new];
    //设置视图的背景透明度
    vi.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0];
    [self.view addSubview:vi];

    vi.sd_layout.topSpaceToView(self.view, SCREENH_HEIGHT / 8.0).centerXEqualToView(self.view).widthRatioToView(self.view, 0.8).autoHeightRatio(1.3);
    //设置昵称,性别,出生日期,手机号,邮箱,登录密码的输入框
#pragma mark - 昵称
    Nametf=[UITextField new];
    //设置提示文字的颜色
    Nametf.placeholder = @"昵称";
    Nametf.textColor=[UIColor lightGrayColor];
    [Nametf setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [vi addSubview:Nametf];
    Nametf.sd_layout.topSpaceToView(vi, 0).leftSpaceToView(vi, 50).widthRatioToView(vi, 0.85).heightIs(50);
    
    //手机标识图
    UIImageView *img2=[UIImageView new];
    img2.image=[UIImage imageNamed:@"register_icon_name_default_hdpi"];
    [vi addSubview:img2];
    img2.sd_layout.topSpaceToView(vi, 5).leftSpaceToView(vi, 0).widthIs(29).heightIs(32);
    
    //设置手机号下面的灰色线
    UIView *vie=[UIView new];
    vie.backgroundColor=[UIColor lightGrayColor];
    [vi addSubview:vie];
    vie.sd_layout.topSpaceToView(vi, 50).leftSpaceToView(vi,0).widthRatioToView(vi, 1).heightIs(0.5);
#pragma mark - 性别
    Sextf2=[UITextField new];
    //设置提示文字的颜色
    Sextf2.placeholder = @"性别";
    Sextf2.textColor=[UIColor lightGrayColor];
    [Sextf2 setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [vi addSubview:Sextf2];
    Sextf2.sd_layout.topSpaceToView(Nametf, 10).leftSpaceToView(vi, 50).widthRatioToView(vi, 0.85).heightIs(50);
    
    //手机标识图
    UIImageView *img3=[UIImageView new];
    img3.image=[UIImage imageNamed:@"register_icon_sex_default_hdpi"];
    [vi addSubview:img3];
    img3.sd_layout.topSpaceToView(Nametf, 15).leftSpaceToView(vi, 0).widthIs(29).heightIs(32);
    
    //设置手机号下面的灰色线
    UIView *vie2=[UIView new];
    vie2.backgroundColor=[UIColor lightGrayColor];
    [vi addSubview:vie2];
    vie2.sd_layout.topSpaceToView(vie2, 55).leftSpaceToView(vi,0).widthRatioToView(vi, 1).heightIs(0.5);
#pragma mark - 出生日期
    Yeartf3=[UITextField new];
    //设置提示文字的颜色
    Yeartf3.placeholder = @"例如1980-02-25";
    Yeartf3.textColor=[UIColor lightGrayColor];
    [Yeartf3 setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [vi addSubview:Yeartf3];
    Yeartf3.sd_layout.topSpaceToView(vie2, 0).leftSpaceToView(vi, 50).widthRatioToView(vi, 0.85).heightIs(50);
    
    //手机标识图
    UIImageView *img4=[UIImageView new];
    img4.image=[UIImage imageNamed:@"register_icon_date_default_hdpi"];
    [vi addSubview:img4];
    img4.sd_layout.topSpaceToView(vie2, 15).leftSpaceToView(vi, 0).widthIs(29).heightIs(32);
    
    //设置手机号下面的灰色线
    UIView *vie3=[UIView new];
    vie3.backgroundColor=[UIColor lightGrayColor];
    [vi addSubview:vie3];
    vie3.sd_layout.topSpaceToView(Yeartf3, 0).leftSpaceToView(vi,0).widthRatioToView(vi, 1).heightIs(0.5);
#pragma mark - 手机号
    Phonetf4=[UITextField new];
    //设置提示文字的颜色
    Phonetf4.placeholder = @"手机号";
    Phonetf4.textColor=[UIColor lightGrayColor];
    [Phonetf4 setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [vi addSubview:Phonetf4];
    Phonetf4.sd_layout.topSpaceToView(vie3, 10).leftSpaceToView(vi, 50).widthRatioToView(vi, 0.85).heightIs(50);
    
    //手机标识图
    UIImageView *img5=[UIImageView new];
    img5.image=[UIImage imageNamed:@"log_icon_phone_default_hdpi"];
    [vi addSubview:img5];
    img5.sd_layout.topSpaceToView(vie3, 15).leftSpaceToView(vi, 0).widthIs(27).heightIs(33);
    
    //设置手机号下面的灰色线
    UIView *vie4=[UIView new];
    vie4.backgroundColor=[UIColor lightGrayColor];
    [vi addSubview:vie4];
    vie4.sd_layout.topSpaceToView(Phonetf4, 0).leftSpaceToView(vi,0).widthRatioToView(vi, 1).heightIs(0.5);
#pragma mark - 邮箱
    Emailtf5=[UITextField new];
    //设置提示文字的颜色
    Emailtf5.placeholder = @"邮箱";
    Emailtf5.textColor=[UIColor lightGrayColor];
    [Emailtf5 setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [vi addSubview:Emailtf5];
    Emailtf5.sd_layout.topSpaceToView(vie4, 10).leftSpaceToView(vi, 50).widthRatioToView(vi, 0.85).heightIs(50);
    
    //手机标识图
    UIImageView *img6=[UIImageView new];
    img6.image=[UIImage imageNamed:@"register_icon_mail_default_hdpi"];
    [vi addSubview:img6];
    img6.sd_layout.topSpaceToView(vie4, 15).leftSpaceToView(vi, 0).widthIs(27).heightIs(32);
    
    //设置手机号下面的灰色线
    UIView *vie5=[UIView new];
    vie5.backgroundColor=[UIColor lightGrayColor];
    [vi addSubview:vie5];
    vie5.sd_layout.topSpaceToView(Emailtf5, 0).leftSpaceToView(vi,0).widthRatioToView(vi, 1).heightIs(0.5);
#pragma mark - 登录密码
    Passwordtf6=[UITextField new];
    //设置提示文字的颜色
    Passwordtf6.placeholder = @"密码";
    Passwordtf6.textColor=[UIColor lightGrayColor];
    [Passwordtf6 setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [vi addSubview:Passwordtf6];
    Passwordtf6.secureTextEntry=YES;
    Passwordtf6.sd_layout.topSpaceToView(vie5, 10).leftSpaceToView(vi, 50).widthRatioToView(vi, 0.85).heightIs(50);
    
    
    
    //手机标识图
    UIImageView *img7=[UIImageView new];
    img7.image=[UIImage imageNamed:@"log_icon_lock_default_hdpi"];
    [vi addSubview:img7];
    img7.sd_layout.topSpaceToView(vie5, 15).leftSpaceToView(vi, 0).widthIs(27).heightIs(32);
    
    //设置手机号下面的灰色线
    UIView *vie6=[UIView new];
    vie6.backgroundColor=[UIColor lightGrayColor];
    [vi addSubview:vie6];
    vie6.sd_layout.topSpaceToView(Passwordtf6, 0).leftSpaceToView(vi,0).widthRatioToView(vi, 1).heightIs(0.5);
#pragma mark - 确认登录密码
    ConfirmPasswordtf7=[UITextField new];
    //设置提示文字的颜色
    ConfirmPasswordtf7.placeholder = @"确认密码";
    ConfirmPasswordtf7.textColor=[UIColor lightGrayColor];
    ConfirmPasswordtf7.secureTextEntry=YES;
    [ConfirmPasswordtf7 setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [vi addSubview:ConfirmPasswordtf7];
    ConfirmPasswordtf7.sd_layout.topSpaceToView(vie6, 10).leftSpaceToView(vi, 50).widthRatioToView(vi, 0.85).heightIs(50);
    
    
    
    //手机标识图
    UIImageView *img8=[UIImageView new];
    img8.image=[UIImage imageNamed:@"log_icon_lock_default_hdpi"];
    [vi addSubview:img8];
    img8.sd_layout.topSpaceToView(vie6, 15).leftSpaceToView(vi, 0).widthIs(27).heightIs(32);
    
    //设置手机号下面的灰色线
    UIView *vie7=[UIView new];
    vie7.backgroundColor=[UIColor lightGrayColor];
    [vi addSubview:vie7];
    vie7.sd_layout.topSpaceToView(ConfirmPasswordtf7, 0).leftSpaceToView(vi,0).widthRatioToView(vi, 1).heightIs(0.5);
#pragma mark - 登录按钮
    //登录跳转按钮
    UIButton *btn=[[UIButton alloc] init];
    btn.backgroundColor=[UIColor orangeColor];
    [btn setTitle:@"注册" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(ZZZ) forControlEvents:UIControlEventTouchUpInside];
    btn.layer.cornerRadius=15;
    btn.layer.masksToBounds=YES;
    [self.view addSubview:btn];
    btn.sd_layout.leftEqualToView(vi).bottomSpaceToView(self.view, 120).topSpaceToView(vi, 50).rightEqualToView(vi).widthIs(320).heightIs(40);
}

//登录按钮点击跳转方法
-(void)ZZZ{
//    //退出新视图--从上往下退出
    [self dismissViewControllerAnimated:YES completion:nil];
    
    AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes=[NSSet setWithObject:@"text/html"];
    //昵称
    NSString *str=Nametf.text;
    //性别判断男为1女为2
    if ([Sextf2.text isEqualToString:@"男"]) {
        sexBool = @"1";
    }else {
        sexBool=@"2";
    }
    //年月份 生日
    NSString *str3=Yeartf3.text;
    //手机号
    NSString *str4=Phonetf4.text;
    //邮箱
    NSString *str5=Emailtf5.text;
    //密码
    NSString *str6=[Passwordtf6.text aci_encryptWithAES];
    NSString *str7=[ConfirmPasswordtf7.text aci_encryptWithAES];

//    sexBool=@"1";
//    NSString *str3=@"1999-02-25";
//    NSString *str4=@"15666161372";
//    NSString *str5=@"1351966300@qq.com";
//    NSString *psw = tf6.text;
//    NSString *str6=[psw aci_encryptWithAES];
//    NSString *str7=[psw aci_encryptWithAES];
//    [a intv]
    NSDictionary *dic=@{@"nickName":str,@"sex":sexBool,@"birthday":str3,@"phone":str4,@"email":str5,@"pwd":str6,@"pwd2":str7};
    [manager POST:@"http://172.17.8.100/movieApi/user/v1/registerUser" parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"%@",responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];
//    [manager POST:@"http://172.17.8.100/movieApi/user/v1/registerUser" parameters:dic headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
//    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//
//        //self.datascoure = responseObject;
//        NSLog(@"数据有,%@",responseObject);
//
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        NSLog(@"%@",error);
//    }
//     ];
    
    
}

@end
